<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录 - 运动商城</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <style>
        body {
            background-color: #f9f9f9;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            color: #212529;
            line-height: 1.5;
        }
        .login-container {
            margin-top: 4rem;
            margin-bottom: 4rem;
        }
        .login-card {
            box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
            border-radius: 12px;
            border: none;
            overflow: hidden;
            max-width: 420px;
            margin: 0 auto;
            background-color: white;
            transition: all 0.3s ease;
        }
        .login-card:hover {
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            transform: translateY(-3px);
        }
        .login-tabs {
            display: flex;
            width: 100%;
            background: linear-gradient(135deg, #2b3a55, #3a4f76);
            padding: 0;
            border-bottom: none;
            margin: 0;
        }
        .login-tabs .nav-item {
            flex: 1;
        }
        .login-tabs .nav-link {
            color: rgba(255, 255, 255, 0.8);
            font-weight: 500;
            padding: 16px 20px;
            border: none;
            border-bottom: 3px solid transparent;
            border-radius: 0;
            transition: all 0.2s ease;
            text-align: center;
            width: 100%;
            display: block;
        }
        .login-tabs .nav-link.active {
            color: white;
            background-color: transparent;
            border-bottom: 3px solid white;
        }
        .login-tabs .nav-link:hover:not(.active) {
            color: white;
            border-bottom: 3px solid rgba(255, 255, 255, 0.5);
        }
        .login-form {
            padding: 2.5rem;
        }
        .form-floating {
            margin-bottom: 1.5rem;
        }
        .form-floating > .form-control {
            padding: 1rem 0.75rem;
            height: calc(3.5rem + 2px);
            line-height: 1.5;
            border: 1px solid #e0e0e0;
        }
        .form-floating > .form-control:focus {
            border-color: #2b3a55;
            box-shadow: 0 0 0 0.25rem rgba(43, 58, 85, 0.15);
        }
        .form-floating > label {
            padding: 1rem 0.75rem;
            color: #6c757d;
        }
        .btn-login {
            background: linear-gradient(135deg, #2b3a55, #3a4f76);
            border: none;
            font-weight: 600;
            padding: 12px;
            border-radius: 6px;
            letter-spacing: 0.5px;
            text-transform: uppercase;
            transition: all 0.3s ease;
            margin-top: 1rem;
            width: 100%;
            box-shadow: 0 4px 12px rgba(43, 58, 85, 0.2);
        }
        .btn-login:hover {
            background: linear-gradient(135deg, #3a4f76, #4a6495);
            box-shadow: 0 6px 18px rgba(43, 58, 85, 0.3);
            transform: translateY(-2px);
        }
        .forgot-password {
            color: #2b3a55;
            text-decoration: none;
            float: right;
            font-size: 0.9rem;
            margin-top: 3px;
            transition: all 0.2s ease;
        }
        .forgot-password:hover {
            color: #3a4f76;
            text-decoration: underline;
        }
        .form-check-input:checked {
            background-color: #2b3a55;
            border-color: #2b3a55;
        }
        .register-hint {
            text-align: center;
            background-color: #f8f9fa;
            padding: 1.5rem;
            border-top: 1px solid #f0f0f0;
            color: #6c757d;
        }
        .register-link {
            color: #2b3a55;
            text-decoration: none;
            font-weight: 600;
            transition: all 0.2s ease;
        }
        .register-link:hover {
            color: #3a4f76;
            text-decoration: underline;
        }
        .tab-content {
            padding: 0;
        }
        .alert-login {
            margin-bottom: 1.5rem;
            border-radius: 6px;
            padding: 0.75rem 1rem;
            border-left: 4px solid #dc3545;
            background-color: #fff8f8;
        }
        .social-login {
            padding-top: 1.5rem;
            margin-top: 1.5rem;
            border-top: 1px solid #f0f0f0;
            text-align: center;
        }
        .social-login-title {
            position: relative;
            margin-bottom: 1.5rem;
            color: #6c757d;
            font-size: 0.9rem;
        }
        .social-login-title:before,
        .social-login-title:after {
            content: "";
            position: absolute;
            top: 50%;
            width: 30%;
            height: 1px;
            background-color: #f0f0f0;
        }
        .social-login-title:before {
            left: 0;
        }
        .social-login-title:after {
            right: 0;
        }
        .social-icons {
            display: flex;
            justify-content: center;
            gap: 1.5rem;
        }
        .social-icon {
            width: 42px;
            height: 42px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 1.2rem;
            transition: all 0.3s ease;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
        }
        .social-icon:hover {
            transform: translateY(-3px);
            box-shadow: 0 6px 12px rgba(0, 0, 0, 0.12);
        }
        .social-icon.wechat {
            background-color: #07C160;
        }
        .social-icon.qq {
            background-color: #12B7F5;
        }
        .social-icon.weibo {
            background-color: #E6162D;
        }
        /* 验证码按钮样式 */
        .verification-code-btn {
            background: linear-gradient(135deg, #2b3a55, #3a4f76);
            color: white;
            border: none;
            font-weight: 500;
            transition: all 0.3s ease;
            box-shadow: 0 4px 12px rgba(43, 58, 85, 0.2);
        }
        .verification-code-btn:hover:not(:disabled) {
            background: linear-gradient(135deg, #3a4f76, #4a6495);
            box-shadow: 0 6px 18px rgba(43, 58, 85, 0.3);
        }
        .verification-code-btn:disabled {
            background: #adb5bd;
            cursor: not-allowed;
        }
        .form-floating i {
            color: #2b3a55;
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <jsp:include page="common/header.jsp"/>
    
    <!-- 登录表单 -->
    <div class="container login-container">
        <div class="row justify-content-center">
            <div class="col-md-6">
                <div class="card login-card">
                    <!-- 登录选项卡 -->
                    <div class="card-header p-0">
                        <ul class="nav nav-tabs login-tabs" id="loginTabs" role="tablist">
                            <li class="nav-item" role="presentation">
                                <a class="nav-link active" id="account-tab" data-bs-toggle="tab" href="#account" role="tab" aria-controls="account" aria-selected="true">账号登录</a>
                            </li>
                            <li class="nav-item" role="presentation">
                                <a class="nav-link" id="sms-tab" data-bs-toggle="tab" href="#sms" role="tab" aria-controls="sms" aria-selected="false">短信登录</a>
                            </li>
                        </ul>
                    </div>
                    
                    <div class="tab-content" id="loginTabsContent">
                        <!-- 账号密码登录 -->
                        <div class="tab-pane fade show active" id="account" role="tabpanel" aria-labelledby="account-tab">
                            <div class="login-form">
                                <div class="alert alert-danger alert-login d-none" id="loginError"></div>
                                
                                <form id="loginForm">
                                    <div class="form-floating mb-4">
                                        <input type="text" class="form-control" id="username" name="username" placeholder="请输入用户名" required>
                                        <label for="username"><i class="fas fa-user me-2"></i>用户名</label>
                                    </div>
                                    
                                    <div class="form-floating mb-4">
                                        <input type="password" class="form-control" id="password" name="password" placeholder="请输入密码" required>
                                        <label for="password"><i class="fas fa-lock me-2"></i>密码</label>
                                    </div>
                                    
                                    <div class="mb-4 d-flex justify-content-between align-items-center">
                                        <div class="form-check">
                                            <input type="checkbox" class="form-check-input" id="rememberMe" name="rememberMe">
                                            <label class="form-check-label" for="rememberMe">记住我</label>
                                        </div>
                                        <a href="#" class="forgot-password">忘记密码?</a>
                                    </div>
                                    
                                    <button type="submit" class="btn btn-primary btn-login">
                                        <i class="fas fa-sign-in-alt me-2"></i>登录
                                    </button>
                                    
                                    <!-- 社交登录 -->
                                    <div class="social-login">
                                        <div class="social-login-title">其他登录方式</div>
                                        <div class="social-icons">
                                            <a href="#" class="social-icon wechat"><i class="fab fa-weixin"></i></a>
                                            <a href="#" class="social-icon qq"><i class="fab fa-qq"></i></a>
                                            <a href="#" class="social-icon weibo"><i class="fab fa-weibo"></i></a>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                        
                        <!-- 短信登录 -->
                        <div class="tab-pane fade" id="sms" role="tabpanel" aria-labelledby="sms-tab">
                            <div class="login-form">
                                <div class="alert alert-danger alert-login d-none" id="smsLoginError"></div>
                                
                                <form id="smsLoginForm">
                                    <div class="form-floating mb-4">
                                        <input type="tel" class="form-control" id="phone" name="phone" placeholder="请输入手机号" required>
                                        <label for="phone"><i class="fas fa-mobile-alt me-2"></i>手机号</label>
                                    </div>
                                    
                                    <div class="input-group mb-4">
                                        <div class="form-floating flex-grow-1">
                                            <input type="text" class="form-control" id="verificationCode" name="verificationCode" placeholder="请输入验证码" required>
                                            <label for="verificationCode"><i class="fas fa-key me-2"></i>验证码</label>
                                        </div>
                                        <button class="btn verification-code-btn" type="button" id="getCodeBtn">获取验证码</button>
                                    </div>
                                    
                                    <button type="submit" class="btn btn-primary btn-login">
                                        <i class="fas fa-sign-in-alt me-2"></i>登录
                                    </button>
                                    
                                    <!-- 社交登录 -->
                                    <div class="social-login">
                                        <div class="social-login-title">其他登录方式</div>
                                        <div class="social-icons">
                                            <a href="#" class="social-icon wechat"><i class="fab fa-weixin"></i></a>
                                            <a href="#" class="social-icon qq"><i class="fab fa-qq"></i></a>
                                            <a href="#" class="social-icon weibo"><i class="fab fa-weibo"></i></a>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    
                    <!-- 注册提示 -->
                    <div class="register-hint">
                        还没有账号? <a href="${pageContext.request.contextPath}/register" class="register-link">立即注册 <i class="fas fa-arrow-right fa-xs"></i></a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- 页脚 -->
    <jsp:include page="common/footer.jsp"/>
    
    <!-- 引入JS -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        $(document).ready(function() {
            // 账号密码登录提交
            $('#loginForm').submit(function(e) {
                e.preventDefault();
                
                $.ajax({
                    url: '${pageContext.request.contextPath}/user/login',
                    type: 'POST',
                    data: {
                        username: $('#username').val(),
                        password: $('#password').val(),
                        rememberMe: $('#rememberMe').is(':checked') ? 1 : 0
                    },
                    success: function(response) {
                        if (response.success) {
                            window.location.href = '${pageContext.request.contextPath}/';
                        } else {
                            $('#loginError').removeClass('d-none').text(response.message);
                        }
                    },
                    error: function() {
                        $('#loginError').removeClass('d-none').text('登录请求失败，请稍后再试');
                    }
                });
            });
            
            // 手机验证码登录
            $('#smsLoginForm').submit(function(e) {
                e.preventDefault();
                
                $.ajax({
                    url: '${pageContext.request.contextPath}/user/smsLogin',
                    type: 'POST',
                    data: {
                        phone: $('#phone').val(),
                        code: $('#verificationCode').val()
                    },
                    success: function(response) {
                        if (response.success) {
                            window.location.href = '${pageContext.request.contextPath}/';
                        } else {
                            $('#smsLoginError').removeClass('d-none').text(response.message);
                        }
                    },
                    error: function() {
                        $('#smsLoginError').removeClass('d-none').text('登录请求失败，请稍后再试');
                    }
                });
            });
            
            // 获取验证码按钮倒计时
            $('#getCodeBtn').click(function() {
                var phone = $('#phone').val();
                if (!phone) {
                    $('#smsLoginError').removeClass('d-none').text('请输入手机号码');
                    return;
                }
                
                var btn = $(this);
                btn.prop('disabled', true);
                var countdown = 60;
                
                $.ajax({
                    url: '${pageContext.request.contextPath}/user/sendSmsCode',
                    type: 'POST',
                    data: {phone: phone},
                    success: function(response) {
                        if (response.success) {
                            var timer = setInterval(function() {
                                countdown--;
                                btn.text(countdown + '秒后重新获取');
                                
                                if (countdown <= 0) {
                                    clearInterval(timer);
                                    btn.prop('disabled', false).text('获取验证码');
                                }
                            }, 1000);
                        } else {
                            btn.prop('disabled', false);
                            $('#smsLoginError').removeClass('d-none').text(response.message);
                        }
                    },
                    error: function() {
                        btn.prop('disabled', false);
                        $('#smsLoginError').removeClass('d-none').text('发送验证码失败，请稍后再试');
                    }
                });
            });
        });
    </script>
</body>
</html> 